package com.yanqu.xiuxian.crosssystem.manger.elementalbonds.entity;



import com.yanqu.xiuxian.config.elementalbonds.enums.ElementalBondsBlockBigType;
import com.yanqu.xiuxian.config.elementalbonds.enums.ElementalBondsBlockType;
import com.yanqu.xiuxian.config.elementalbonds.enums.ElementalBondsColorType;
import com.yanqu.xiuxian.config.elementalbonds.enums.ElementalBondsDirectionType;

import java.util.ArrayList;
import java.util.List;

public class ElementalBondsBlock {

    private int x;
    private int y;
    private int color;

    private ElementalBondsBlockType elementalBondsBlockType = ElementalBondsBlockType.NORMAL;
    private List<ElementalBondsBlockEffect> elementalBondsBlockEffectList = new ArrayList<>();
    private ElementalBondsDirectionType elementalBondsDirectionType = ElementalBondsDirectionType.UP;

    // 消除后获得
    private int score;
    private int sp;

    public ElementalBondsBlock() {

    }

    public ElementalBondsBlock(int x, int y, int color) {
        this.x = x;
        this.y = y;
        this.color = color;
    }

    public ElementalBondsBlock(int x, int y, ElementalBondsColorType elementalBondsColorType) {
        this.x = x;
        this.y = y;
        this.color = elementalBondsColorType.getType();
    }

    public static ElementalBondsBlock createFrame(int x, int y, ElementalBondsBlockType elementalBondsBlockType) {
        if (elementalBondsBlockType.getBigType() != ElementalBondsBlockBigType.FRAME) {
            throw new RuntimeException("这个类型不是框");
        }

        ElementalBondsBlock elementalBondsBlock = new ElementalBondsBlock(x, y, ElementalBondsColorType.NONE);
        elementalBondsBlock.setElementalBondsBlockType(elementalBondsBlockType);
        return elementalBondsBlock;
    }

    public void addElementalBondsBlockEffect(ElementalBondsBlockEffect elementalBondsBlockEffect) {
        if (elementalBondsBlockEffectList.stream().noneMatch(effect ->
                effect.getEffectType() == effect.getEffectType())) {
            this.elementalBondsBlockEffectList.add(elementalBondsBlockEffect);
        }
    }

    public ElementalBondsBlock clone() {
        ElementalBondsBlock elementalBondsBlock = new ElementalBondsBlock(getX(), getY(), getColor());

        elementalBondsBlock.setElementalBondsBlockType(getElementalBondsBlockType());

        List<ElementalBondsBlockEffect> elementalBondsBlockEffectList = new ArrayList<>();
        for (ElementalBondsBlockEffect elementalBondsBlockEffect : getElementalBondsBlockEffectList()) {
            elementalBondsBlockEffectList.add(elementalBondsBlockEffect.clone());
        }
        elementalBondsBlock.setElementalBondsBlockEffectList(elementalBondsBlockEffectList);

        elementalBondsBlock.setElementalBondsDirectionType(getElementalBondsDirectionType());
        elementalBondsBlock.setScore(getScore());
        elementalBondsBlock.setSp(getSp());

        return elementalBondsBlock;
    }

    public int getX() {
        return x;
    }

    public void setX(int x) {
        this.x = x;
    }

    public int getY() {
        return y;
    }

    public void setY(int y) {
        this.y = y;
    }

    public int getColor() {
        return color;
    }

    public void setColor(int color) {
        this.color = color;
    }

    public ElementalBondsBlockType getElementalBondsBlockType() {
        return elementalBondsBlockType;
    }

    public void setElementalBondsBlockType(ElementalBondsBlockType elementalBondsBlockType) {
        this.elementalBondsBlockType = elementalBondsBlockType;
    }

    public List<ElementalBondsBlockEffect> getElementalBondsBlockEffectList() {
        return elementalBondsBlockEffectList;
    }

    public void setElementalBondsBlockEffectList(List<ElementalBondsBlockEffect> elementalBondsBlockEffectList) {
        this.elementalBondsBlockEffectList = elementalBondsBlockEffectList;
    }

    public ElementalBondsDirectionType getElementalBondsDirectionType() {
        return elementalBondsDirectionType;
    }

    public void setElementalBondsDirectionType(ElementalBondsDirectionType elementalBondsDirectionType) {
        this.elementalBondsDirectionType = elementalBondsDirectionType;
    }

    public int getScore() {
        return score;
    }

    public void setScore(int score) {
        this.score = score;
    }

    public int getSp() {
        return sp;
    }

    public void setSp(int sp) {
        this.sp = sp;
    }
}
